package com.telit.firecommand.controller;

import com.telit.common.entity.DataReturn;
import com.telit.common.util.JwtTokenUtils;
import com.telit.firecommand.dto.IssueFireVerificationTask;
import com.telit.firecommand.dto.PushFireMsg;
import com.telit.firecommand.entity.FireDisposalInfo;
import com.telit.firecommand.service.FireDisposalInfoService;
import com.telit.firecommand.service.UserInfoService;
import com.telit.firecommand.service.impl.FireDisposeServiceImpl;
import com.telit.upms.vo.MicroSysUserAllInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Auther chencf
 * @description 火情处置信息接口
 **/
@RestController
@RequestMapping("/fire-disposal")
@Api(tags = "火情处置接口", description = "/fire-disposal")
public class FireDisposalInfoController {

    @Autowired
    private FireDisposalInfoService fireDisposalInfoService;

    @Autowired
    private FireDisposeServiceImpl fireDisposeService;

    @Autowired
    private UserInfoService userInfoService;

    @GetMapping(value = "/queryFireDisposalInfoByFireId/{fireId}", produces = "application/json;charset=UTF-8")
    @ApiOperation("根据火情id查询火情处置信息")
    public DataReturn queryFireDisposalInfoByFireId(@PathVariable("fireId") Long fireId) {
        List<FireDisposalInfo> fireDisposalInfo = fireDisposalInfoService.queryFireDisposalInfoByFireId(fireId);
        return DataReturn.ok(fireDisposalInfo);
    }

    @PostMapping(value = "/addFireDispose", produces = "application/json;charset=UTF-8")
    @ApiOperation("添加火情处置信息")
    public DataReturn addFireDispose(@RequestBody PushFireMsg pushFireMsg) {
        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
        fireDisposeService.processDisposeInfo(pushFireMsg, userInfo);
        return DataReturn.ok();
    }

    @PostMapping(value = "/addTaskDispose", produces = "application/json;charset=UTF-8")
    @ApiOperation("添加火情核实任务处置信息")
    public DataReturn addTaskDispose(@RequestBody IssueFireVerificationTask issueFireVerificationTask) {
        Long id = JwtTokenUtils.getId();
        MicroSysUserAllInfoVo userInfo = userInfoService.getUserInfo(id);
        fireDisposeService.processDisposeInfo(issueFireVerificationTask, userInfo);
        return DataReturn.ok();
    }

}
